import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Method;
import java.nio.file.LinkOption;

public class ClassLoaderFrame extends JFrame {

    private JTextField keyField=new JTextField("3",4);
    private JTextField nameField=new JTextField("Calculator",30);
    private static final int DEFAULT_WIDTH=300;
    private static final int DEFAULT_HEIGHT=200;
    public ClassLoaderFrame()
    {
        setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
        setLayout(new GridBagLayout());
       // add(new JLabel("Class"),new GBC(0,0).setAnchor(GBC.EAST));
      //  add(nameField,new GBC(1,0).setWeight(100,0).setAnchor(GBC.WEST));


        var loadButton=new JButton("Load");
       // add(loadButton,new GBC(0,2,2,1));
        loadButton.addActionListener(event->runClass(nameField.getText(),keyField.getText()));
        pack();
    }
    public void runClass(String name,String key)
    {
        try
        {
            var loader=new CryptoClassLoader(Integer.parseInt(key));
            Class<?> c=loader.loadClass(name);
            Method m=c.getMethod("main",String[].class);
            m.invoke(null,(Object) new String[] {});
        }
        catch (Throwable t)
        {
            JOptionPane.showMessageDialog(this,t);
        }
    }

}
